package com.z.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.z.base.vo.PageVo;
import com.z.blog.entity.Tag;
import com.z.blog.mapper.TagMapper;
import com.z.blog.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 博客标签Service业务层处理
 *
 * @author z
 * @date 2022-08-31
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {

    @Autowired
    private TagMapper tagMapper;
    @Override
    public List<Tag> listTagTop(int top) {
        PageHelper.startPage(1, top);
        return baseMapper.selectList( new QueryWrapper<Tag>());
    }

    /**
     * 查询博客标签
     * @param tag 博客标签
     * @param pageVo
     * @return 博客标签 分页集合
     * */
    @Override
    public PageInfo<Tag> selectTagPage(Tag tag, PageVo pageVo) {
        PageHelper.startPage(pageVo.getPage(), pageVo.getLimit());
        List<Tag> data = baseMapper.selectTagList(tag);
        return new PageInfo<>(data);
    }


    @Override
    public List<Integer> getIdsByBlogId(Long id) {
        return tagMapper.getIdsByBlogId(id);
    }

    @Override
    public List<Tag> getTagsByBlogId(Long id) {
        return tagMapper.getTagsByBlogId(id);
    }
}
